package day01;
import javax.swing.text.html.Option;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.sql.Array;
import java.util.*;
import java.util.List;

public class ReviewLessons02 {
    public static void main(String[] args) {
        /*
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int[][] arr = new int[num][num];
        for (int i = 0; i < num; i++) {
            for (int j = num-i-1; j > 0; j--) {
                System.out.print(" ");
            }
            for (int k=0;k<=i;k++){
                System.out.print(arr[i][k]+" ");
            }
            System.out.println();
        }
         */

        /*
        //Set 不可有重复
        Set<String> s =new HashSet<>();
        s.add("ote");
        s.add("two");
        s.add("three");
        s.add("four");
        s.add("five");
        s.add("ote");
        System.out.println(s);//[ote, four, two, three, five]

        List<String> l =new ArrayList<>();
        l.add("ote");
        l.add("two");
        l.add("three");
        l.add("four");
        l.add("five");
        l.add("ote");
        System.out.println(l);//[ote, two, three, four, five, ote]
        //重，添加
        Set<String> s1 = new HashSet<>();
        s1.addAll(l);
        System.out.println(s1);//[ote, four, two, three, five]
         */

        /*
        List<String> l1 = new ArrayList<>();
        l1.add("王skd");
        l1.add("李sklasdj");
        l1.add("东sjd");
        l1.add("和ssjsd");
        System.out.println(l1);

        Collections.sort(l1, ( o1, o2)-> {
                return o1.length()-o2.length();
        });
        System.out.println(l1);

        List<String> l2 = new ArrayList<>();
        l2.add("sjdlks");
        l2.add("xjsdj");
        l2.add("apsdks");
        l2.add("vmc");
        l2.add("sdjk");
        System.out.println(l2);
        Collections.sort(l2);
        System.out.println(l2);

        List<Point> p = new ArrayList<>();
        p.add(new Point(22,9));
        p.add(new Point(25,5));
        p.add(new Point(22,8));
        p.add(new Point(66,50));
        p.add(new Point(18,9));
        p.add(new Point(33,3));
        System.out.println(p);
        //按x元素升序
        p.sort((o1,o2) ->{
                return o1.getX()-o2.getX();
        });
        System.out.println(p);
        //按x*x+y*y的元素降序
        p.sort((o1,o2)->{
            int a = o1.getX()* o1.getX()+o1.getY()*o1.getY();
            int b = o2.getX()* o2.getX()+o2.getY()*o2.getY();
            return b-a;
        });
        System.out.println(p);
         */

        /*
        Random r =new Random();
        List<Integer> l = new ArrayList<>();
        for (int i=0;i<10;i++){
            l.add(r.nextInt(100));
        }
        System.out.println(l);
        Collections.sort(l);//升序
        System.out.println(l);
        Collections.reverse(l);//反转
        System.out.println(l);
         */

        /*
        //List常规方法
        List<String> l = new ArrayList<>();
        l.add("one");
        l.add("two");
        l.add("three");
        l.add("four");
        l.add("five");
        System.out.println("原数据:"+l);//[one, two, three, four, five]
        String s = l.get(3);//下标找元素
        System.out.println(s);//four
        String s1 = l.set(3,"java");//替换并返回
        System.out.println(s1);//four
        System.out.println(l);//[one, two, three, java, five]
        String s2 = l.remove(2);//删除并返回
        System.out.println(s2);//three
        System.out.println(l);//[one, two, java, five]
        l.add(3,"php");//指定并插入
        System.out.println(l);//[one, two, java, php, five]

        List<Integer> l2 = new ArrayList<>();
        for (int i=0;i<10;i++){
            l2.add(i*10);
        }
        System.out.println(l2);//[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
        List<Integer> l3 = l2.subList(2,8);//子集
        System.out.println(l3);//[20, 30, 40, 50, 60, 70]
        l3.set(3,200);//子集修改
        System.out.println(l3);//[20, 30, 40, 200, 60, 70]
        System.out.println(l2);//[0, 10, 20, 30, 40, 200, 60, 70, 80, 90]
         */

        /*
        //泛型
        Collection<Point> c = new ArrayList<>();
        c.add(new Point(1,2));
        c.add(new Point(3,4));
        c.add(new Point(5,6));
        c.add(new Point(7,8));
        System.out.println(c);

        Iterator<Point> i = c.iterator();
        while(i.hasNext()){
             Point p1 = i.next();
             System.out.println(p1);
        }
        for (Point p2 : c){
            System.out.println(p2);
        }
        //集合转换为数组
        Point[] p = c.toArray(new Point[4]);
        System.out.println(Arrays.toString(p));
        for (int k=0;k<p.length;k++){
            System.out.println("数组:"+p[k]);
        }
        //数组转换为集合
        List<Point> l = Arrays.asList(p);
        System.out.println(l);
         */

        /*
        //新循环
        String[] s = {"one","two","three","four","five"};
        for (int i=0;i<s.length;i++){
            System.out.println("s="+s[i]);
        }
        for (String s1 : s){
            System.out.println("s1="+s1);
        }
        Collection c = new ArrayList();
        c.add("ont");
        c.add("twe");
        c.add("three");
        c.add("four");
        c.add("five");

        Iterator i = c.iterator();
        while (i.hasNext()){
            String s2 = (String)i.next();
            System.out.println("s2="+s2);
        }
        for (Object o : c){
            String s3 = (String)o;
            System.out.println("s3="+s3);
        }
         */

        /*
        //迭代器
        Collection c6 = new ArrayList();
        c6.add("one");
        c6.add("*");
        c6.add("two");
        c6.add("*");
        c6.add("three");
        c6.add("*");
        c6.add("four");
        c6.add("*");
        c6.add("five");
        System.out.println(c6);

        Iterator i = c6.iterator();
        while(i.hasNext()){
            String i1 = (String)i.next();
            System.out.println(i1);
            if ("*".equals(i1)){
                i.remove();
            }
        }
        System.out.println(c6);
         */

        /*
        //Collection接口常用方法
        Collection c = new ArrayList();
        c.add("hello");//添加
        c.add("world");
        c.add("java");
        System.out.println(c);//[hello, world, java]
        System.out.println(c.size());//3  返回个数
        System.out.println(c.isEmpty());//false   判断是否为空集   空集表示0
        boolean s1 = c.contains("java");//判断是否有这个元素
        System.out.println(s1);//true
        c.remove("world");//删除这个元素
        System.out.println(c);//[hello, java]
        c.clear();//清空元素
        System.out.println(c);//[]
        System.out.println(c.isEmpty());//true  判断是否为空集

        Collection c2 = new ArrayList();
        c2.add("java");
        c2.add("睡觉");
        c2.add("c++");
        System.out.println(c2);//[java, 睡觉, c++]
        Collection c3 = new ArrayList();
        c3.add("吃饭");
        c3.add("喝水");
        c3.add("no");
        System.out.println(c3);//[吃饭, 喝水, no]
        c2.addAll(c3);
        System.out.println(c2);//[java, 睡觉, c++, 吃饭, 喝水, no]
        System.out.println(c3);//[吃饭, 喝水, no]
        Collection c4 = new ArrayList();
        c4.add("c++");
        c4.add("no");
        System.out.println(c4);//[c++, no
        boolean b1 = c2.containsAll(c4);//判断是否有这些元素
        System.out.println(b1);//true
        c3.retainAll(c4);//取交集
        System.out.println(c3);//[no]
        System.out.println(c4);//[c++, no]
        System.out.println(c2);//[java, 睡觉, c++, 吃饭, 喝水, no]
        c2.removeAll(c4);//删交集
        System.out.println(c2);//[java, 睡觉, 吃饭, 喝水]
        System.out.println(c4);//c++, no]
         */

        /*
        //String转换int类型
        String s = "123";
        int i = Integer.parseInt(s);
        System.out.println(i);
        //需要重写equals    重写toString
        Point p = new Point(10,50);
        Point p1 = new Point(20,50);
        Point p2 = new Point(10,50);
        System.out.println(p);
        System.out.println(p.equals(p2));
        //String 重写了equals
        String s = "hello";
        String s1 = "hello";
        System.out.println(s.equals(s1));
        //String 没重写equals
        StringBuilder s3 = new StringBuilder("hello");
        StringBuilder s4 = new StringBuilder("hello");
        System.out.println(s3.equals(s4));
         */

        /*
        //String常用方法
        int i = 123;
        double d = 123.456;
        String s = "  Hello World I Love Java 123";
        int s1 = s.length();//长度
        String s2 = s.trim();//去除两边空白字符
        String s3 = s.toUpperCase();//转大写
        String s4 = s.toLowerCase();//转小写
        boolean s5 = s.startsWith("e");//判断开始
        boolean s6 = s.endsWith("a");//判断结束
        char s7 = s.charAt(6);//根据位置找字符
        int s8 = s.indexOf("l");//第一次出现的位置
        int s9 = s.lastIndexOf("r");//最后一次出现的位置
        String s10 = String.valueOf(i);//转换String类型
        String s11 = String.valueOf(d);//转换String类型
        String s12 = s.substring(6,20);//截取
        String s13 = "xioawang@qq.on";
        String s14 = "[a-zA-Z0-9_]+@[a-zA-Z]+(\\.[a-zA-Z]+)+";
        boolean s15 = s13.matches(s14);//判断是否匹配
        String s16 = s.replaceAll("[0-9]+","*");//替换
        String[] s17 = s.split(" ");//将集合拆分
        System.out.println(Arrays.toString(s17));//集合转换为数组
        System.out.println(s1);

        String s18 = "我爱java，我爱学习，我爱c++";
        StringBuilder s19 = new StringBuilder(s18);//String转StringBuilder
        s19.append(",我爱干净");//追加       我爱java，我爱学习，我爱c++,我爱干净
        s19.delete(9,14);//删除             爱java，我爱c++,我爱干净
        s19.replace(7,11,"我想睡觉");//修改      我爱java，我想睡觉+,我爱干净
        s19.insert(12,"我想吃饭");//插入    我爱java，我想睡觉+我想吃饭,我爱干净
        String s20 = s19.toString();//StringBuilder转String
        System.out.println(s19);
         */

        /*
        //扩容
        int[] a = new int[10];
        for (int i=0;i<a.length;i++){
             a[i] = (int)(Math.random()*100);
        }
        for (int i=0;i<a.length;i++){
            System.out.println(a[i]);
        }
        a = Arrays.copyOf(a,a.length+3);
        for (int i=0;i<a.length;i++){
            System.out.println(a[i]);
        }
         */

        /*
        //定时器
        Timer t = new Timer();
        int a = 2000;
        t.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("该学习了");
            }
        }, a);
         */

        /*
        //素数
        for (int num=2;num<=100;num++){
            boolean b = true;
            for (int i=2;i<=num/2;i++){
                if (num%i==0){
                    b = false;
                    break;
                }
            }
            if (b){
                System.out.println(num);
            }
        }
         */

        /*
        //猜大小
        Scanner sc = new Scanner(System.in);
        System.out.println("数字小游戏");
        int a = (int)(Math.random()*1000);
        System.out.println(a);
        while(true){
            int b = sc.nextInt();
            if (a<b){
                System.out.println("猜大了");
            }else if (a>b){
                System.out.println("猜小了");
            }else{
                System.out.println("猜对了");
                break;
            }
        }
         */

    }

    /*
    //获取验证码
    public static void main(String[] args) {
        String s = ss(6);
        System.out.println(s);
    public static String ss(int len){
        String s = "";
        char[] c = {'a','b','c','d','e','f','g','h','i','j','k', 'l','m','n',
                'o','p','q','r','s','t','u','v', 'w','x','y','z','A','B','C','D',
                'E','F','G', 'H','I','J','K','L','M','N','O','P','Q','R', 'S','T',
                'U','V','W','X','Y','Z','0','1','2', '3','4','5','6','7','8','9'};
        Random r = new Random();
        for (int i=0;i<len;i++){
            int a = r.nextInt(c.length);
            s+=c[a];
        }
        return s;
    }
     */

        /*
        //总分，平均分
        double[] d = Pss();
        double c = cc(d);
        System.out.println(c);

    }
    public static double[] Pss(){
        double[] d = new double[6];
        for (int i=0;i<d.length;i++){
            System.out.println("第"+(i+1)+"位评委打分");
            Scanner sc = new Scanner(System.in);
            d[i] = sc.nextDouble();
        }
        return d;
    }
    public static double ss(double[] d){
        double c = 0.0;
        double max = d[0];
        double min = d[0];
        for (int i=0;i<d.length;i++){
            c += d[i];
            if (max<d[i]){
                max = d[i];
            }
            if(min>d[i]){
                min = d[i];
            }
        }
        return c-max-min;
    }
    public static double cc(double[] d){
        double a = ss(d);
        double b = a/(d.length-2);
        return b;
    }
         */

        /*
        //机票价格
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入机票原价:");
        double price = scan.nextDouble();
        System.out.println("请输入月份:");
        int month = scan.nextInt();
        System.out.println("请选择舱位: 1.头等舱 2.商务舱 3.经济舱");
        int type = scan.nextInt();

        double p = Psd(price,month,type);
        System.out.println(p);
    }
    public static double Psd(double price,int month,int type){
        double f = 0.0;
        if (month>12||month<1){
            System.out.println("月份输入有错");
            return -1;
        }
        if (type>3||type<1){
            System.out.println("舱位有错");
            return -1;
        }
        if (month>=5&&month<10){
            switch(type){
                case 1:
                    f = price*0.9;
                    break;
                case 2:
                    f = price*0.85;
                    break;
                case 3:
                    f = price*0.8;
                    break;
            }
        }else {
            switch(type) {
                case 1:
                    f = price * 0.7;
                    break;
                case 2:
                    f = price * 6.5;
                    break;
                case 3:
                    f = price * 6;
                    break;
            }
        }
        return f;
         */
}